/**
 * 
 */
package hu.gbalage.owlforms.xforms;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;

/**
 * @author Grill Balazs (balage.g@gmail.com)
 *
 */
public class InToOut implements HttpHandler {

	/* (non-Javadoc)
	 * @see com.sun.net.httpserver.HttpHandler#handle(com.sun.net.httpserver.HttpExchange)
	 */
	@Override
	public void handle(HttpExchange arg0) throws IOException {
		
		arg0.sendResponseHeaders(200, 0);
		
		InputStream is = arg0.getRequestBody();
		
		OutputStream os = arg0.getResponseBody();
		
		/*while(is.available() > 0){
			os.write(is.read());
		}*/
		
		byte[] bytes = new byte[is.available()];
		is.read(bytes);
		os.write(bytes);
		
		arg0.close();
	}

}
